package com.jz.community.moduleshopping.shopCart.adapter;

import android.support.annotation.Nullable;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.android.arouter.launcher.ARouter;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jz.community.basecomm.bean.baseGoods.BaseGoodsInfo;
import com.jz.community.basecomm.routerUtils.RouterIntentConstant;
import com.jz.community.basecomm.utils.BaseImageLoaderUtils;
import com.jz.community.basecomm.utils.CharacterUtils;
import com.jz.community.basecomm.utils.ConverterUtils;
import com.jz.community.basecomm.utils.Preconditions;
import com.jz.community.basecomm.utils.RxTextTool;
import com.jz.community.basecomm.utils.SHelper;
import com.jz.community.moduleshopping.R;

import java.util.List;

public class TogetherGoodsAdapter extends BaseQuickAdapter<BaseGoodsInfo.EmbeddedBeanXX.ContentBeanX, BaseViewHolder> {


    public TogetherGoodsAdapter(int layoutResId, @Nullable List<BaseGoodsInfo.EmbeddedBeanXX.ContentBeanX> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, BaseGoodsInfo.EmbeddedBeanXX.ContentBeanX item) {
        ImageView shopping_guide_grid_iv = helper.getView(R.id.shopping_guide_grid_iv);
        TextView shopping_guide_grid_name = helper.getView(R.id.shopping_guide_grid_name);
        TextView shopping_guide_grid_persons = helper.getView(R.id.shopping_guide_grid_persons);
        TextView shopping_guide_grid_price = helper.getView(R.id.shopping_guide_grid_price);
        TextView shopping_guide_dis_price = helper.getView(R.id.shopping_guide_dis_price);
        shopping_guide_grid_persons.setText(item.getSaleCount() + "位邻居已购买");
        if (item.getSkuInfos() != null && item.getSkuInfos().size() > 0) {
            if (!Preconditions.isNullOrEmpty(item.getSkuInfos())) {
                if (!Preconditions.isNullOrEmpty(item.getSkuInfos().get(0).getDiscountPrice())) {
                    shopping_guide_grid_price.setText(CharacterUtils.roundByGoodPrice(ConverterUtils.toDouble(item.getSkuInfos().get(0).getDiscountPrice())));
                    RxTextTool.getBuilder("").append(CharacterUtils.roundByGoodPrice(ConverterUtils.toDouble(item.getSkuInfos().get(0).getPrice()))).setStrikethrough().into(shopping_guide_dis_price);
                    SHelper.vis(shopping_guide_dis_price);
                } else {
                    shopping_guide_grid_price.setText(CharacterUtils.roundByGoodPrice(ConverterUtils.toDouble(item.getSkuInfos().get(0).getPrice())));
                    SHelper.gone(shopping_guide_dis_price);
                }
            }
        }
        BaseImageLoaderUtils.getInstance().loadRamdomImage(mContext, shopping_guide_grid_iv, item.getIcon());
        shopping_guide_grid_name.setText(item.getTitle());
        RelativeLayout rl = helper.getView(R.id.rl_shopping_guide_item);
        rl.setOnClickListener(v -> ARouter.getInstance()
                .build(RouterIntentConstant.MODULE_SHOPPING_GOODS_DETAIL)
                .withString("url", item.get_links().getSelf().getHref())
                .navigation());
    }
}
